package com.coco.goods.controller;

import com.coco.goods.pojo.TbGoods;
import com.coco.goods.pojo.TbItem;
import com.coco.goods.service.GoodsService;
import com.coco.goods.service.ItemService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * controller
 * @Author: guofeng
 * @Date: 2021/07/14/20:46
 * @Description:
 */
@Api
@RestController
@RequestMapping("/item")
public class ItemController {

    @Autowired
    private ItemService itemService;

    /**
     * 增加
     * @param
     * @return
     */
    @RequestMapping("/add")
    public void add(@RequestBody TbItem item){
        try {
            itemService.add(item);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @RequestMapping("/delete")
    public void delete(Long [] ids){
        try {
            itemService.delete(ids);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 修改
     * @param item
     * @return
     */
    @RequestMapping("/update")
    public void update(@RequestBody TbItem item){
        try {
            itemService.update(item);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取实体
     * @param id
     * @return
     */
    @RequestMapping("/findOne/{id}")
    public TbItem findOne(@PathVariable Long id){
       return itemService.findOne(id);
    }

    /**
     * 返回全部列表
     * @return
     */
    @RequestMapping("/findAll")
    public List<TbItem> findAll(){
       return itemService.findAll();
    }


    /**
     * 返回全部列表带条件
     * @return
     */
    @RequestMapping("/findAllSearch")
    public List<TbItem> findAll(@RequestBody TbItem item){
        return itemService.findAll(item);
    }

    /**
     * 查询+分页
     * @param
     * @return
     */
    @RequestMapping("/search")
    public List<TbItem> search(@RequestBody TbItem item){
       return itemService.findAllSearch(item);
    }
}



